cmake_policy(SET CMP0057 NEW)

# Add current list dir to CMAKE_MODULE_PATH to enable find package of installed modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})

#--------------------------- Base configuration for installation and rpath settings ----------------

# --------------------------------------------------------------------------------------------------
# Load Radium rpath configuration
include(${CMAKE_CURRENT_LIST_DIR}/RPath.cmake)

# --------------------------------------------------------------------------------------------------
# Configure components

# Load Radium cmake functions
include(${CMAKE_CURRENT_LIST_DIR}/RadiumSetupFunctions.cmake)

@PACKAGE_INIT@

# manage components
set(Radium_supported_components @RADIUM_COMPONENTS@)
if(Radium_FIND_COMPONENTS)
    # Components are requested, fetch them and their dependencies
    foreach(component ${Radium_FIND_COMPONENTS})
        if(${component} IN_LIST Radium_supported_components)
            set(${component}_FOUND True)
            if(NOT TARGET ${component})
                include("${CMAKE_CURRENT_LIST_DIR}/${component}/Radium${component}Config.cmake")
            endif()
        else()
            set(Radium_FOUND False)
            set(Radium_NOT_FOUND_MESSAGE "Unsupported component: ${component}")
        endif()
    endforeach()
else()
    # No component is requested, fetch only Core
    set(Core_FOUND True)
    if(NOT TARGET Core)
        include("${CMAKE_CURRENT_LIST_DIR}/Core/RadiumCoreConfig.cmake")
    endif()
endif()

if(NOT TARGET Core)
     # Compute paths
    get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)
    # get up in the directories until we found a "Resources/Radium" subdir TODO : instead of
    # 'Resources/Radium' that might not exists if Engine nor Gui are compiled, search for a file
    # identifying Radium (a la Eigen) and that is installed at the root of the Radium Bundle
    while(NOT EXISTS ${SELF_DIR}/Resources/Radium)
        get_filename_component(SELF_DIR "${SELF_DIR}" DIRECTORY)
    endwhile()

    set(RADIUM_CONFIG_DIR ${CMAKE_CURRENT_LIST_DIR})
    set(RADIUM_ROOT_DIR "${SELF_DIR}")
else()
    set(RADIUM_CONFIG_DIR ${CMAKE_CURRENT_LIST_DIR})
    set(RADIUM_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}")
endif()
set(RADIUM_RESOURCES_DIR "${RADIUM_ROOT_DIR}/Resources/Radium")
set(RADIUM_PLUGINS_DIR "${RADIUM_ROOT_DIR}/Plugins")
